<template>
  <!-- 用户购买流量明细 -->
  <div style="padding: 10px;">
    <el-card>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item :label="$t('用户id')">
          <el-input size="small" v-model="formInline.userId"></el-input>
        </el-form-item>
        <el-form-item :label="$t('用户邮箱')">
          <el-input size="small" v-model="formInline.email"></el-input>
        </el-form-item>
        <el-form-item :label="$t('状态')">
          <el-select size="small" v-model="formInline.status">
            <el-option :label="$t('无效')" :value="0"></el-option>
            <el-option :label="$t('有效')" :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('创建时间')">
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="formInline.createTime"
            size="small"
            type="datetime"
            :placeholder="$t('选择日期时间')"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="onSubmit">{{ $t('query') }}</el-button>
          <el-button size="small" type="warning" @click="reset">{{ $t('重置') }}</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-table style="margin-top: 10px;" v-loading="loading" :data="tableData">
      <el-table-column prop="userId" :label="$t('用户id')"></el-table-column>
      <el-table-column prop="email" :label="$t('用户邮箱')"></el-table-column>
      <el-table-column prop="flowId" :label="$t('购买流量包类型')">
        <template #default="{ row }">
          <span v-if="+row.flowId === 1">{{ $t('初级流量包') }}</span>
          <span v-else-if="+row.flowId === 2">{{ $t('中级流量包') }}</span>
          <span v-else-if="+row.flowId === 3">{{ $t('高级流量包') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="flowNumber" :label="$t('购买流量包个数')"></el-table-column>
      <el-table-column prop="flowPrice" :label="$t('流量包单价')"></el-table-column>
      <!-- <el-table-column prop="floWAmount" :label="$t('用户总资产')"></el-table-column> -->
      <el-table-column prop="floWAmount" :label="$t('总购买金额')">
        <template #default="{ row }">{{ row.flowNumber * row.flowPrice }}</template>
      </el-table-column>
      <!-- <el-table-column prop="balanceAmount" :label="$t('用户结余资产')"></el-table-column> -->
      <el-table-column prop="status" :label="$t('状态')">
        <template #default="{ row }">{{ row.status ? $t('有效') : $t('无效') }}</template>
      </el-table-column>
      <el-table-column prop="createTime" :label="$t('创建时间')"></el-table-column>
    </el-table>
    <el-pagination
      style="float: right;margin: 5px 0;"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      layout="total, prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import { getflowBagdetailApi } from "@/api/appuser/userList";
export default {
  data() {
    return {
      page: {
        pageNum: 1,
        pageSize: 10
      },
      formInline: {
        userId: null,
        email: null,
        status: null,
        createTime: null
      },
      tableData: [],
      total: 0,
      loading: false
    };
  },
  created() {
    this.getflowBagdetail();
  },
  methods: {
    async getflowBagdetail() {
      this.loading = true;
      const res = await getflowBagdetailApi({
        ...this.page,
        ...this.formInline
      });
      console.log(res);
      this.total = res.total;
      this.tableData = res.rows;
      this.loading = false;
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getflowBagdetail();
    },
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.getflowBagdetail();
    },
    onSubmit() {
      this.page = {
        pageNum: 1,
        pageSize: 10
      };
      console.log(this.formInline);
      this.getflowBagdetail();
    },
    reset() {
      this.page = {
        pageNum: 1,
        pageSize: 10
      };
      this.formInline = {
        userId: null,
        email: null,
        status: null,
        createTime: null
      };
      this.getflowBagdetail();
    }
  }
};
</script>
<style lang='' scoped>
</style>